package com.zhan.drugStore.filter;

import com.zhan.drugStore.constant.LogConstant;
import com.zhan.drugStore.util.ToolUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;



@Slf4j
@WebFilter(urlPatterns = "/*")
public class HttpTraceIdFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        String tid = ToolUtils.genUUID();
        MDC.put(LogConstant.TID,tid);
        filterChain.doFilter(servletRequest, servletResponse);
        MDC.remove(LogConstant.TID);
    }
}
